function myRandom() {
  let a = [];
  for (let i = 0; i < arguments.length; i += 2) {
    a.push(
      Math.floor(
        Math.random() * (arguments[i + 1] - arguments[i] + 1) + arguments[i]
      )
    );
  }
  return a[Math.floor(Math.random() * a.length)];
  // return a;
}
function randomString(cnt) {
  let arr = [];
  for (let i = 0; i < cnt; i++) {
    let index = myRandom(48, 57, 65, 90, 97, 122);
    let c = String.fromCharCode(index);
    arr.push(c);
  }
  return arr.join("");
}
function createParentChain(key, parentArr) {
  //针对树状结构数据查找key并返回其父级链条（数组），节点值为value属性，子节点数组为children属性
  for (let i = 0; i < parentArr.length; i++) {
    const parentNode = parentArr[i];
    // console.log(parentNode);
    if (parentNode.value == key) {
      return [key];
    }
    if (parentNode.children) {
      const childRes = map(key, parentNode.children, parentNode.value);
      if (childRes) {
        return [parentNode.value, ...childRes];
      }
    }
  }

  return; // 没找到返回undefined
}
module.exports = { myRandom, randomString, createParentChain };
